package com.qf.springboot.demoredis.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;

/**
 * @Auther: Adrian
 * @Date: 2020/3/9 18:24
 * @Description:
 */
@SpringBootConfiguration
public class RedisConfig {
    private Logger logger= LoggerFactory.getLogger(RedissonClient.class);

    @Bean
    public RedissonClient redissonClient(){
        RedissonClient redissonClient=null;
        //获取config的实例
        Config config = new Config();
        //设置请求的URL地址
        String url="redis://192.168.30.133:6379";
        //设置config
        config.useSingleServer().setAddress(url);
        //通过Redisson来创建一个客户端对象
        try{
            redissonClient= Redisson.create(config);
            logger.info("创建RedissonClient成功");
            return redissonClient;
        }catch (Exception err){
            logger.info("创建RedissonClient失败:"+err.fillInStackTrace());
            return null;
        }
    }
}
